home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / RevRdist Folder / RevRdist / RevRdist src / getset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-07  |  6.2 KB  |  256 lines  |  [TEXT/KAHL]

  1. /*
  2.  * getset.c - code to check that we have all the files,
  3.  * etc needed to run
  4.  */
  5. #include "RevRdist.h"
  6. #include "desktop.h"
  7. #include "volops.h"
  8.  
  9.  
  10. /*
  11.  *=========================================================================
  12.  * getSet - make sure we have enough information to proceed
  13.  * returns:    0 if all set
  14.  *            <> 0 if something missing
  15.  *            Quit may or may not be set
  16.  *=========================================================================
  17.  */
  18.  
  19. OSErr
  20. getSet()
  21. {
  22.     OSErr                error;
  23.     cnode_t                *cn;            /* ptr to fi->f_info */
  24.     file_info_t            *fi;            /* temp ptr into File_list[] */
  25.     prefs_t                *pp;            /* ptr to working prefs structure */
  26.     StringHandle        sh;                /* temp string handle */
  27.     StringPtr            sp;                /* ptr into mi Data area */
  28.     StringPtr            st;                /* string temp */
  29.     int                    t;                /* temp */
  30.     Integer                vol;            /* volume reference temp */
  31.     HParamBlockRec        hpb;            /* for GetVInfo, etc calls */
  32.     Str255                s;                /* string temp */
  33.     AFPVolMountInfo        mi;                /* server volume information */
  34.  
  35.     desktop_end();
  36.     ServerVol = 0;
  37.     fi = &File_list[FL_PREF];
  38.     cn = &fi->f_info;
  39.     if (fi->f_set)
  40.     {
  41.     /*
  42.      * If prefs file from launch, fetch values from it.
  43.      * The file had better be there.
  44.      */
  45.         if (fi->f_launch)
  46.         {
  47.             fi->f_launch = false;    /* get only one shot */
  48.             error = prefFFetch (fi);
  49.             if (error)
  50.             {
  51.                 sh = fi->f_path;
  52.                 HLock ((Handle) sh);
  53.                 panic (true, E_PREFS, *sh, nil);
  54.                 HUnlock ((Handle) sh);
  55.                 return error;
  56.             }
  57.             prefMerge (P_WORK, true);
  58.         }
  59.     }
  60.     /*
  61.      * Figure out where the server master folder is.
  62.      * Its name (absolute path) is a preferences resource.
  63.      * If mounting/unmounting of server volumes is allowed, set up
  64.      * mi structure
  65.      */
  66.     pp = &Prefs[P_WORK];
  67.     sh = pp->p[PS_MASTF];
  68.     if (!sh)
  69.     {
  70.         panic (true, E_NOSERVER, nil);
  71.         return E_NOSERVER;
  72.     }
  73.     COPYPS (*sh, s);
  74.     ZERO(mi);
  75.     mi.length = sizeof(mi);
  76.     mi.media = AppleShareMediaType;
  77.     if (!(Flags & PF_NOMOUNT))
  78.     {
  79.         /*
  80.          * Need to temporarily logically shorten master folder name to just
  81.          * volume name
  82.          */
  83.         t = s[0];                    /* current length */
  84.         st = (StringPtr)strchr((char *)s+1, ':');
  85.         if (st)
  86.             (*sh)[0] = st - (s+1);
  87.         sp = (StringPtr)mi.AFPData;
  88. #define    COPYPREF(ii,ee) \
  89.         sh = pp->p[ii]; \
  90.         if (sh && (st = *sh) && st[0] && st[0] < 32) \
  91.             COPYPS(st, sp); \
  92.         mi.ee = sp - (StringPtr)(&mi); \
  93.         sp += 32;
  94.  
  95.         COPYPREF(PS_ZONE, zoneNameOffset);
  96.         if (sp[-32+0] == 0)
  97.         {
  98.             sp[-32+1] = '*';        /* supply default zone name */
  99.             sp[-32+0] = 1;
  100.         }
  101.         COPYPREF(PS_SRVR, serverNameOffset);
  102.         COPYPREF(PS_MASTF, volNameOffset);
  103.         st[0] = t;                    /* restore length */
  104.         COPYPREF(PS_USER, userNameOffset);
  105.         COPYPREF(PS_PASS, userPasswordOffset);
  106. #undef    COPYPREF
  107.     }
  108.     error = accessMaster (s, &mi);
  109.     Clue0 = "\pgetSet";
  110.     if (error)
  111.     {
  112.         ClueID = error;
  113.         if (error == fnfErr || error == nsvErr || error == dirNFErr)
  114.             panic (true, E_NOSERVER, s, nil);
  115.         else if (error == afpAccessDenied)
  116.             panic (true, E_NOACCESS, s, nil);
  117.         else
  118.             panic (true, E_SYS, Clue0, "\paccessMaster", nil);
  119.     }
  120.     if (error || Quit)
  121.         return error;
  122.     fi = &File_list[FL_MAST];
  123.     cn = &fi->f_info;
  124.     error = getInfoByPath (s, fi);
  125.     if (error)
  126.     {
  127.         ClueID = error;
  128.         panic (true, E_SYS, Clue0, "\pgetInfoByPath", nil);
  129.     }
  130.     if (error || Quit)
  131.         return error;
  132.     ServerVol = fi->f_vol;
  133.     ServerRoot = fi->f_info.dirID;
  134.     ZERO (hpb);
  135.     s[0] = 0;
  136.     hpb.volumeParam.ioNamePtr = s;
  137.     hpb.volumeParam.ioVRefNum = ServerVol;
  138.     error = PBHGetVInfo (&hpb, false);
  139.     if (error)
  140.     {
  141.         ClueID = error;
  142.         panic (true, E_SYS, Clue0, "\pPBHGetVInfo", nil);
  143.     }
  144.     ZERO(ServerVIB);
  145.     hpb.ioParam.ioBuffer = (Ptr) &ServerVIB;
  146.     hpb.ioParam.ioReqCount = sizeof (ServerVIB);
  147.     error = PBHGetVolParms (&hpb, false);
  148.     if (error && error != paramErr)
  149.     {
  150.         ClueID = error;
  151.         panic (true, E_SYS, Clue0, "\pPBHGetVolParms (S)", nil);
  152.     }
  153. //    /*
  154. //     * Set master folder as default volume
  155. //     */
  156. //    error = SetVol (s, ServerVol);
  157.     /*
  158.      * If we don't have a config file yet, locate it via preferences
  159.      */
  160.     fi = &File_list[FL_DIST];
  161.     cn = &fi->f_info;
  162.     if (! fi->f_set)
  163.     {
  164.         sh = Prefs[P_WORK].p[PS_DISTF];
  165.         if (!sh)
  166.         {
  167.             panic (true, E_DISTF, (SP)"", nil);
  168.             return fnfErr;
  169.         }
  170.         HLock ((Handle) sh);
  171.         fi->f_vol = 0;
  172.         error = getInfoByPath (*sh, fi);
  173.         if (error)
  174.         {
  175.             panic (true, E_DISTF, *sh, nil);
  176.             HUnlock ((Handle) sh);
  177.             return error;
  178.         }
  179.         HUnlock ((Handle) sh);
  180.     }
  181.     /*
  182.      * okay, now find the volume to update.
  183.      * If FINDUPD flag, it is first writeable, non-floppy, non-weird volume
  184.      * else it is the volume containing the preferences file, if present,
  185.      * else the volume containing a distribution file used to launch us,
  186.      * else the volume with the the blessed folder.
  187.      */
  188.     error = 0;
  189.     if (Flags & PF_FINDUPD)
  190.         error = findWvol (s, FF_WRITE|FF_NOSONY|FF_NOXFS|FF_NOASHARE, &vol);
  191.     else if (File_list[FL_PREF].f_set)
  192.         vol = File_list[FL_PREF].f_vol;
  193.     else if (File_list[FL_DIST].f_launch)
  194.         vol = File_list[FL_DIST].f_vol;
  195.     else
  196.         vol = BlessedWD;
  197.     fi = &File_list[FL_ROOT];
  198.     fi->f_ref = vol;
  199.     fi->f_info.ctype = C_FOLDER;
  200.     s[0] = 0;
  201.     if (error == 0)
  202.         error = getInfoByPath (s, fi);
  203.     if (error)
  204.     {
  205.         panic (true, E_NOVOL, nil);
  206.         return E_NOVOL;
  207.     }
  208.     ClientVol = fi->f_vol;
  209.     ClientRoot = fsRtDirID;
  210.     COPYPS (fi->f_info.name, ClientVolName);
  211.     /*
  212.      * Make sure that client is HFS volume
  213.      * Save volume size information
  214.      */
  215.     ZERO (hpb);
  216.     s[0] = 0;
  217.     hpb.volumeParam.ioNamePtr = s;
  218.     hpb.volumeParam.ioVRefNum = ClientVol;
  219.     PBHGetVInfo (&hpb, false);
  220.     if (hpb.volumeParam.ioVSigWord == 0xD2D7)
  221.     {
  222.         panic (true, E_MFS, CurApName, s, nil);
  223.         return E_MFS;
  224.     }
  225.     ClientSp = (unsigned long)(unsigned)hpb.volumeParam.ioVFrBlk
  226.             * (unsigned)hpb.volumeParam.ioVAlBlkSiz;
  227.     ClientClp = hpb.volumeParam.ioVClpSiz;
  228.     ClientClpM = ClientClp - 1;        /* assumes ClientClp is power of 2 */
  229.     /*
  230.      * Check if the client volume is writeable
  231.      * If not, warn and set ListOnly
  232.      */
  233.     if (!(Flags & PF_LISTONLY) && (hpb.volumeParam.ioVAtrb & 0x8080))
  234.     {
  235.         warning (E_LISTONLY, s, nil);
  236.         Flags |= PF_LISTONLY;
  237.     }
  238.     ZERO(ClientVIB);
  239.     hpb.ioParam.ioBuffer = (Ptr) &ClientVIB;
  240.     hpb.ioParam.ioReqCount = sizeof (ClientVIB);
  241.     error = PBHGetVolParms (&hpb, false);
  242.     if (error && error != paramErr)
  243.     {
  244.         ClueID = error;
  245.         panic (true, E_SYS, Clue0, "\pPBHGetVolParms (C)", nil);
  246.     }
  247.     error = desktop_start();
  248.     if (error)
  249.         return error;
  250.     /*
  251.      * Create/access junk folder.
  252.      * If fails, just warn about it.
  253.      */
  254.     error = makeJunk ();
  255.     return error;
  256. }